package com.rulin.asp.business.controller;

import java.util.List;

import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.rulin.asp.business.entity.QuestionAdminResultRow;
import com.rulin.asp.business.entity.QuestionParam;
import com.rulin.asp.business.service.DictionaryService;
import com.rulin.asp.business.service.QuestionService;
import com.rulin.asp.util.Tools;

/**
 * 教师端答疑检索功能
 * @author yangsy
 *
 */
@Controller
@RequestMapping("/teacherController")
public class TeacherController {

	@Autowired
	private QuestionService questionService;
	
	@Autowired
	private DictionaryService dictionaryService;
	
	@RequestMapping(value = "/quesListPage.html", method = RequestMethod.GET)
	public String quesListPage(Model model){
		setDiv(model);
		return "business/teacher/searchlist";
	}
	
	public void setDiv(Model model){
		model.addAttribute("quesTypes", dictionaryService.getByModel("ques_type_param"));
		model.addAttribute("quesDiffLevels", dictionaryService.getByModel("ques_diff_level"));
		
		model.addAttribute("questionSources", dictionaryService.getByModel("question_source"));
		model.addAttribute("quesBookClasses", dictionaryService.getByModel("ques_book_class"));
		model.addAttribute("quesBookClasses1", dictionaryService.getByModel("ques_book_class_1"));
		model.addAttribute("quesBookClasses2", dictionaryService.getByModel("ques_book_class_2"));
		model.addAttribute("quesBookClasses3", dictionaryService.getByModel("ques_book_class_3"));
		model.addAttribute("userTypes", dictionaryService.getByModel("user_type"));
		model.addAttribute("quesBookClasses4", dictionaryService.getByModel("ques_book_class_4"));
	}
	
	@RequestMapping(value = "/getList.json", method = RequestMethod.GET)
	@ResponseBody
	public String list(QuestionParam bean){
		Pair<Integer,List<QuestionAdminResultRow>> pair= questionService.getTeacherQuesListByParam(bean);
		return Tools.toEasyuiDataGrid(pair.getLeft(), pair.getRight());
	}
	
	@RequestMapping(value = "/openReadPage.html", method = RequestMethod.GET)
	public String openReadPage(Model model,String quesId){
		setDiv(model);
		model.addAttribute("form", questionService.getQuestion(quesId));
		return "business/teacher/question-read";
	}
}
